package com.aliyun.codeupdemo.controller;

import com.alibaba.fastjson.JSON;
import com.aliyun.codeupdemo.model.Greeter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class ScannerController {

    @RequestMapping("/")
    public String index() {
        Random r = new Random();
        int randInt = r.nextInt();

        Greeter greeter = new Greeter();
        greeter.setFirstName("Codeup");
        greeter.setLastName("Yunxiao");
        greeter.setAge(2);
        System.out.println(JSON.toJSONString(greeter));

        if (randInt % 2 == 0)
            return greeter.getFirstName() + ":" +  helloWorld;

        return HELLO_WORLD;
    }

    private String helloWorld = "Welcome to Codeup";

    private static final String HELLO_WORLD = "Nice to meet you";
}